package com.ttg.web.dao.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ttg.common.dto.TagProducer;
import com.ttg.model.mapper.BankCustomerSignInfoMapper;
import com.ttg.model.pojo.BankCustomerSignInfo;
import com.ttg.web.dao.BankCustomerSignInfoDao;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class BankCustomerSignInfoDaoImpl extends ServiceImpl<BankCustomerSignInfoMapper, BankCustomerSignInfo> implements BankCustomerSignInfoDao {
    @Override
    public List<BankCustomerSignInfo> getByCstId(String cstId) {
        LambdaQueryWrapper<BankCustomerSignInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BankCustomerSignInfo::getCstId,cstId);

        return list(queryWrapper);
    }

    @Override
    public BankCustomerSignInfo getByCstIdAndSignServer(String cstId, String signServer) {
        LambdaQueryWrapper<BankCustomerSignInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(BankCustomerSignInfo::getId);
        queryWrapper.eq(BankCustomerSignInfo::getCstId, cstId);
        queryWrapper.eq(BankCustomerSignInfo::getSignServer, signServer);
        return getOne(queryWrapper);
    }

    @Override
    public Map<String, Long> existsMapByCtsIdAndSignServer(List<Map<String, String>> existsWhere) {
        if (CollectionUtils.isEmpty(existsWhere)) {
            return Collections.emptyMap();
        }
        Map<String, Long> rsMap = new HashMap<>();
        for (BankCustomerSignInfo bankCustomerSignInfo : baseMapper.existsMapByCtsIdAndSignServer(existsWhere)) {
            rsMap.put(bankCustomerSignInfo.getCstId() + bankCustomerSignInfo.getSignServer(), bankCustomerSignInfo.getId());
        }
        return rsMap;
    }

    @Override
    public List<Long> getVipIdsByTags(List<TagProducer> tags, String key) {
        return baseMapper.getVipIdsByTags(tags, key);
    }

    @Override
    public void truncate() {
        baseMapper.truncate();
    }
}
